@extends('admin.layouts.app')
@section('css')
<link href="{{asset('assets/plugins/switchery/css/switchery.min.css')}}" rel="stylesheet" />
@endsection
@section('content')
@include('vendor.ueditor.assets')
                        <!-- Page-Title -->
                        <div class="row">
                            <div class="col-sm-12">
                                <h4 class="page-title">平台管理</h4>
                                <ol class="breadcrumb">
                                    <li><a href="#">系统</a></li>
                                    <li><a href="{{url('zadmin/products')}}">商品管理</a></li>
                                    <li class="active">修改商品</li>
                                </ol>
                            </div>
                        </div>
                        
                        <div class="row">
                        	<div class="col-lg-12">
                        		<div class="card-box">
                            <h2 class="m-t-0 header-title">修改商品</h2>
                            <hr/>
                             
                              @include('admin.common.error')
                        			<div class="row">
			                        	<div class="col-md-9">
                                  <form class="form-horizontal" role="form" action="{{url('zadmin/products/update')}}" method="post">
                                              <div class="form-group">
                                                  <label class="col-md-2 control-label">商品名</label>
                                                  <div class="col-md-10">
                                                      <input type="text" class="form-control" name="name" required="" value="{{$data->name}}" >
                                                  </div>
                                              </div>
                                             <div class="form-group">
                                                  <label class="col-md-2 control-label">分类</label>
                                                  <div class="col-md-10">
                                                      <select class="form-control" name="cate_id">
                                                        <option value="">请选择</option>
        @foreach($cates as $cate)
        <option value="{{$cate->id}}" {{$data->cate_id==$cate->id?'selected':''}}>{{$cate->name}}</option>
        @endforeach
                                                      </select>
                                                  </div>
                                              </div>
                                              <div class="form-group">
                      <label class="col-md-2 control-label">吊牌价</label>
                    <div class="col-md-4">
                      <input type="text" class="form-control" name="market_price" required="" value="{{$data->market_price}}" >
                    </div>
                                             
                      <label class="col-md-2 control-label">零售价</label>
                                <div class="col-md-4">
                      <input type="text" class="form-control" name="price" required="" value="{{$data->price}}" >
                                                  </div>
                      
                                                
                                              </div>
                                              <div class="form-group">
                                                  <label class="col-md-2 control-label">状态</label>
                                                  <div class="col-md-10">
                <select  class="form-control" name="status" required="" >
                  <option value="1" {{$data->status==1?'selected':''}}>销售中</option>
                  <option value="0" {{$data->status==0?'selected':''}}>已下架</option>
                </select>
                                                  </div>
                                              </div>
                 <div class="form-group">
                                                  <label class="col-md-2 control-label">首页推荐</label>
                                                  <div class="col-md-10">
                <select  class="form-control" name="is_rec" required="" >
                  <option value="1" {{$data->is_rec==1?'selected':''}}>推荐</option>
                  <option value="0" {{$data->is_rec==0?'selected':''}}>不推荐</option>
                </select>
                                                  </div>
                </div> 

                   <div class="form-group">
              <label class="col-md-2 control-label">介绍</label>
              <div class="col-md-10">
               <!-- 实例化编辑器 -->
<script type="text/javascript">
    var ue = UE.getEditor('container');
    ue.ready(function() {
        ue.execCommand('serverparam', '_token', '{{ csrf_token() }}'); // 设置 CSRF token.
    });
</script>

<!-- 编辑器容器 -->
<script id="container" name="contents" type="text/plain">{!!$data->contents!!}</script>
              </div>
            </div> 
   

                                        
                 <div class="form-group">
                    <label class="control-label col-md-2">上传图片</label>
                    <div class="col-md-10">
                      <div id="filelist"></div>

                      <div class="piclist"></div>
                                                                   
                      <button class="btn" type="button" id="pickfiles">选择图片</button>
                    </div>
                 
                                                       
                                                 
                </div>                               

                <div class="form-group">
                        <label class=" col-md-2 control-label">图片</label>                                   
                        <div class="col-md-10"> 

                          @foreach($data->imgs as $pic)
                          <div class="col-md-4" style="margin:  10px;">
                            <img src="{{$pic->imgurl}}"  height="100" style="padding: 5px;" />
                            <p>
                            <a href="{{url('zadmin/products/thumb')}}?product_id={{$data->id}}&pic={{$pic->imgurl}}" class="btn btn-info btn-sm">设为封面</a>
                            <a href="{{url('zadmin/products/img-delete?id='.$pic->id)}}" class="btn btn-danger btn-sm">删除</a>
                          </p>
                          </div>
                          @endforeach
                        </div>  
                        
                                                       
                                                 
                    </div>                               
                                              

                                              

                                              <div class="form-group text-center">
                                                  
                                                  <button type="submit" class="btn btn-info waves-effect waves-light">保存</button>
                                              </div>
                                              
                             <input name="id" value="{{$data->id}}" type="hidden" />                 
                             {{csrf_field()}}

                             <input name="pics" id="pics" type="hidden" value=""  />
                        </form>
                                </div>
			                        	
			                        </div>

                             
			                        
                        			
                        		</div>
                                
                            </div> <!-- end col -->

                            
                        </div>
@endsection
                        
                        
                        

                  
            
         
       

           



    
        @section('js')
  <script type="text/javascript" src="/js/plupload.full.min.js"></script>
  <script type="text/javascript" src="{{asset('assets/plugins/switchery/js/switchery.min.js')}}"></script>
        <script type="text/javascript">
        var pics = '';
          var uploader = new plupload.Uploader({
              runtimes : 'html5,flash,silverlight,html4',
              browse_button : 'pickfiles',               
              url : '/upload.php',
              flash_swf_url : '../js/Moxie.swf',
              silverlight_xap_url : '../js/Moxie.xap',
              
              filters : {
                max_file_size : '10mb',
                mime_types: [
                  {title : "Image files", extensions : "jpg,gif,png"},
                  {title : "Zip files", extensions : "zip"}
                ]
              },

              init: {
                PostInit: function() {
                  $('#filelist').html('');

                  
                },

                FilesAdded: function(up, files) {
                  plupload.each(files, function(file) {
                    $('#filelist').html('<div id="' + file.id + '">' + file.name + ' (' + plupload.formatSize(file.size) + ') <b></b></div>');
                     uploader.start();
                     return false;
                  });
                },

               

                 FileUploaded: function(up, file, info) {
                    // Called when file has finished uploading
                    var rs =  JSON.parse(info.response);
                    if(rs.status){
                      var str = '<img style="padding:5px" src="'+rs.data+'" width="100">';
                      $('.piclist').append(str);
                      pics += rs.data+',';
                      $('#pics').val(pics);
                    }
                    console.info(rs);                              
                },
              }
          });
      uploader.init();


      $('#openspec').on('change',function(){
            var val = $(this).prop('checked');
            var id = $(this).data('id');
            if(val==false) {
              $('.spec-table').show();
              
            } else {
              $('.spec-table').hide();
            }
            //alert(val);
          })

       $(document).on('click','.spec-add',function(){
         var _tr = $('.spec-tr:first').clone();
         $('.spec-table').append(_tr);
       })

       $(document).on('click','.spec-del',function(){
         var _length = $('.spec-tr').length;
         if(_length==1) return ;
         console.info(_length);
         $(this).parents('tr').remove();
       })
</script>      
@endsection
    
